package ch03.shiLi.shiLi8;


import java.lang.reflect.Proxy;

public class IntermediaryJdkProxyFactory {
    /**工厂方法
     * target 需要被代理的目标对象
     */
    public static <T> T create(Object target){
        //IntermediaryInvocationHandler的成员变量target存在线程安全问题，
        //故将IntermediaryInvocationHandler作为局部变量使用
        IntermediaryInvocationHandler handler = new IntermediaryInvocationHandler();
        handler.setTarget(target);
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),handler);
    }

}
